#include <iostream>
#include <queue>

using namespace std;

struct BTreeNode // a node in the binary tree
{
      int         m_nValue; // value of node
      BTreeNode  *m_pLeft;  // left child of node
      BTreeNode  *m_pRight; // right child of node
};

void PrintFromTopToBottom(BTreeNode *pTreeRoot)
{
	queue<BTreeNode *> q;
	q.push(pTreeRoot);
	while(!q.empty())
	{
		BTreeNode *front = q.front();
		cout<<front->m_nValue<<" ";
		if(front->m_pLeft)
			q.push(front->m_pLeft);
		if(front->m_pRight)
			q.push(front->m_pRight);
		q.pop();
	}
	cout<<endl;
}

int main()
{
	struct BTreeNode a8, a6, a10, a5, a7, a9 ,a11;

  a8.m_nValue = 8;
  a8.m_pLeft = &a6;
  a8.m_pRight = &a10;

  a6.m_nValue = 6;
  a6.m_pLeft = &a5;
  a6.m_pRight = &a7;

  a10.m_nValue = 10;
  a10.m_pLeft = &a9;
  a10.m_pRight = &a11;

  a5.m_nValue = 5;
  a5.m_pLeft = NULL;
  a5.m_pRight = NULL;

  a7.m_nValue = 7;
  a7.m_pLeft = NULL;
  a7.m_pRight = NULL;

  a9.m_nValue = 9;
  a9.m_pLeft = NULL;
  a9.m_pRight = NULL;

  a11.m_nValue = 11;
  a11.m_pLeft = NULL;
  a11.m_pRight = NULL;

	PrintFromTopToBottom(&a8);	
}
